package whf.framework.report.jasper;

import java.io.OutputStream;
import java.util.Map;

import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import whf.framework.util.Utils;

/**
 * @author King
 * @create Jan 18, 2008 2:45:25 PM
 */
public class ExcelJasperReportExporter extends JasperReportExporter {

	/* (non-Javadoc)
	 * @see whf.framework.report.jasper.JasperReportExporter#exportReport(net.sf.jasperreports.engine.JasperPrint, java.io.OutputStream)
	 */
	@Override
	protected void exportJasperReport(JasperPrint jasperPrint, OutputStream out) throws Exception {
		JRXlsExporter exporter = new JRXlsExporter();
		exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
		//exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, reportFile + xlsFileName); // 输出到文件
		exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out); // 输出到流
		exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); // 每页使用一个SHEET
		exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); // 移除空白
		exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); // 背景色
		exporter.exportReport();
	}

	/* (non-Javadoc)
	 * @see whf.framework.report.ReportExporter#getContentType()
	 */
	public String getContentType() {
		return "application/vnd.ms-excel;charset=utf-8";
	}

	/* (non-Javadoc)
	 * @see whf.framework.report.ReportExporter#getHeaders()
	 */
	public Map<String, String> getHeaders() {
		Map<String, String> result = Utils.newHashMap();
		result.put("Content-disposition", "attachment; filename=" + this.reportDescriptor.getFileName());
		return result;
	}

}
